import java.util.LinkedList;
import java.util.Queue;

public class CreatBT {
    public TreeNode creatBinaryTree(int[] nums) {
        TreeNode cur = new TreeNode(nums[0]);
        TreeNode root = cur;
        Queue<TreeNode> queue = new LinkedList<>();
        int i = 0;
        while (cur != null){
            //如果左子树存在
            if (2*i+1 < nums.length){
                cur.left = new TreeNode(nums[2*i+1]);
                queue.offer(cur.left);
            }
            //如果右子树存在
            if (2*i+2 < nums.length){
                cur.right = new TreeNode(nums[2*i+2]);
                queue.offer(cur.right);
            }
            cur = queue.poll();
            i += 1;
        }
        return root;
    }

    public static void main(String[] args) {
        CreatBT c = new CreatBT();
        int[] nums = {1,2,3,4,5,6,78,};
        TreeNode root = c.creatBinaryTree(nums);
    }
}
